package com.kornero.auto.view.groups;

import com.kornero.auto.util.view.LayoutManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class EmailGroupImpl extends Composite implements IEmailGroup {

    private static final Logger logger = LoggerFactory.getLogger(EmailGroupImpl.class);

    private Text email;
    private Button emailSubscriptionEnabled;
    private Button markAllAsAlreadyRead;

    public EmailGroupImpl(Composite parent) {
        this(parent, SWT.NONE);
    }

    public EmailGroupImpl(Composite parent, int style) {
        super(parent, style);
        this.constructUI();
    }

    private void constructUI() {
        this.setLayout(new FillLayout());
        this.setLayoutData(LayoutManager.getLayoutDataFillVertical());

        final Group group = new Group(this, SWT.NONE);
        group.setLayout(LayoutManager.getFillVerticalLayout());
        group.setText("Email subscription");

        final Composite composite = new Composite(group, SWT.NONE);
        composite.setLayout(new RowLayout());

        new Label(composite, SWT.NONE).setText("Email: ");
        this.email = new Text(composite, SWT.BORDER);
        this.email.setText("UpdateChecker@mail.ru");

        composite.pack();

        this.emailSubscriptionEnabled = new Button(group, SWT.CHECK);
        this.emailSubscriptionEnabled.setText("emailSubscriptionEnabled");
        this.emailSubscriptionEnabled.setLocation(50, 20);

        this.markAllAsAlreadyRead = new Button(group, SWT.NONE);
        this.markAllAsAlreadyRead.setText("markAllAsAlreadyRead");

        group.pack();
    }

    @Override
    public boolean isSendEmails() {
        return this.emailSubscriptionEnabled.getSelection();
    }

    @Override
    public String getEmail() {
        return this.email.getText();
    }

    @Override
    public void addMarkAll(Listener listener) {
        this.markAllAsAlreadyRead.addListener(SWT.MouseDown, listener);
    }
}